/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.ttt.nor2.db;

import com.ttt.nor2.util.ExceptionUtil;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Hashtable;
import org.apache.log4j.Logger;

/**
 *
 * @author anuphabm
 */
public class HtbBulksms {

    private Connection conn;
    private Logger logger = Logger.getLogger(HtbBulksms.class);
    private Bulksms bsms;

    public HtbBulksms(Connection conn) {
        logger.debug("Strart class " + HtbBulksms.class);
        this.conn = conn;

    }

    public Hashtable loadBulk() {
        Hashtable htb = new Hashtable();

        String sql = "select * from bulk";
        try {
            PreparedStatement pstmt = conn.prepareStatement(sql);
            ResultSet rs = pstmt.executeQuery();
            while (rs.next()) {
                bsms = new Bulksms();
                bsms.setUsername(rs.getString("username"));
                bsms.setPassword(rs.getString("password"));
                bsms.setUrl(rs.getString("url"));
                bsms.setScript(rs.getString("script"));
                bsms.setPort(rs.getInt("port"));
                if (rs.getString("urlproxy") != null) {
                    bsms.setProxy(true);
                    bsms.setUrlproxy(rs.getString("urlproxy"));
                    bsms.setPortproxy(rs.getInt("portproxy"));
                } else {
                    bsms.setProxy(false);
                }
                logger.debug("[" + rs.getString("bulkid") +"[" + rs.getString("username") + "][" + rs.getString("password") + "][" + rs.getString("url") + "][" + rs.getString("script") + "][" + rs.getInt("port") + "][" + rs.getString("urlproxy") + "]");
                htb.put(rs.getString("bulkid"), bsms);
            }//end while

        } catch (SQLException ex) {
            logger.error("Exception error " + ExceptionUtil.getStackTrace(ex));
        }


        return htb;
    }
}
